- content_for :head do
  = javascript_include_tag  'mootools-1.2.1-core.js'
  = javascript_include_tag  'mootools-1.2-more.js'
  %script{:type => "text/javascript"}
    = "window.addEvent('domready', function() {"
    = " var stretchers = $$('div.options');"
    = " var togglers = $$('h3.options');"
    = " var order_accordion = new Accordion(togglers, stretchers, {"
    = "   alwaysHide:true,"
    - if params[:process] == "checkout"
      = "   display:0,"
    - else
      = "   display:1,"
    = "   opacity: true,"
    = "   onActive: function(togglers, stretchers){"
    = "     togglers.setStyle('background-image', 'url(/images/assets/more.png) 100% 0% no-repeat');"
    = "     togglers.setStyle('color', '#FFFFFF');"
    = "     togglers.setStyle('cursor', 'pointer');"
    = "   },"
    = "   onBackground: function(togglers, stretchers){"
    = "     togglers.setStyle('background-image', 'url(/images/assets/less.png) 100% 0% no-repeat');"
    = "     togglers.setStyle('color', '#CCCCCC');"
    = "     togglers.setStyle('cursor', 'pointer');"
    = "   }"
    = " }, $('content'));"
    = "});"
- if params[:process] == "checkout"
  %h2 Checkout
  %p 
    Below are the items you have in your cart. Please review your order carefully before you check out. You can go back to 
    %a{:href => user_orders_url, :title => "Your Shopping Cart"} your shopping cart
    if you need to make changes.
- elsif params[:process] == "shopping_cart"
  %h2 Shopping cart
- elsif params[:display] == "completed"
  %h2 Completed Orders
- else
  %h2 Order Items
%div.orders
  - if @orders.empty?
    %p There are no items in your shopping cart at this time.
  - @orders.each do |order|
    - if order.user == current_user || current_user.is_admin?
      %table.order{:id => "order_#{order.id}"}
        %tr
          %td{:colspan => 4}
            %table.order_header
              %tr
                %td.order_number="Order \##{order.id}" 
                %td.order_status
        - form_for order, order_url(order) do |form|
          - if order.items.empty?
            %tr
              %td{:colspan => 4} There are no items in your shopping cart at this time.
          - else
            - order.items.each do |item|
              - if item.photo
                %input{:type => "hidden", :value => item.photo.id, :name => "order[order_items][#{item.id}][photo_id][]"}
                %tr
                  %td.item_metadata
                    %table.item_metadata{:border => 0}
                      %tr
                        %td.added_on{:colspan => 2}
                          Added on
                          = item.created_at.strftime("%B %o at %I:%M %p")
                          by
                          %a{:href => user_url(item.user), :title => "#{item.user.login}'s profile"}= item.user.login
                      - unless (params[:process] == "checkout") || (item.protected? && !current_user.is_admin?)
                        %tr.remove
                          %td.remove remove
                          %td.check_box= check_box_tag("order[order_items][#{item.id}][remove][]", 1)
                      - if item.protected?
                        %tr
                          %td
                          %td
                            %img.lock{:src => lock_image, :title => "This photo is locked into your cart because it required retouching by the photographer.", :alt => "This photo can not be removed"}
                  %td.order_photo
                    %table.photo
                      %tr
                        %td.photo
                          %a{:href => photo_url(item.photo), :title => (item.photo.caption ? item.photo.caption : item.photo.filename), :alt => (item.photo.caption ? item.photo.caption : item.photo.filename)}
                            %img.photo_thumb{:src => item.photo.public_filename(:thumb), :title => (item.photo.caption ? item.photo.caption : item.photo.filename), :alt => (item.photo.caption ? item.photo.caption : item.photo.filename)}
                  %td
                    %table.item_info
                      %tr
                        %td.field_title Quantity:
                        %td.field
                          - unless (params[:process] == "checkout") || (item.protected? && !current_user.is_admin?)
                            %select{:name => "order[order_items][#{item.id}][quantity][]"}
                              - quantities.each do |quantity|
                                %option{:value => quantity, :selected => ('selected' if quantity.to_s == item.quantity.to_s)}= quantity
                          - else
                            %input{:type => "hidden", :value => item.quantity.to_s, :name => "order[order_items][#{item.id}][quantity][]"}
                            = item.quantity.to_s
                      %tr  
                        %td.field_title Size:
                        %td.field
                          - unless (params[:process] == "checkout") || (item.protected? && !current_user.is_admin?)
                            %select{:name => "order[order_items][#{item.id}][photo_size_id][]"}
                              - item.price_list.photo_sizes.each do |photo_size|
                                %option{:value => photo_size.id, :selected => ('selected' if photo_size == item.photo_size)}="#{photo_size.size} ($#{to_money(photo_size.cost)})"
                          - else
                            %input{:type => "hidden", :value => item.photo_size.id.to_s, :name => "order[order_items][#{item.id}][photo_size_id][]"}
                            = "#{item.photo_size.size} ($#{to_money(item.photo_size.cost)})"
                      - if current_user.is_admin?
                        %tr
                          %td.field_title Price List:
                          %td.field
                            - unless (params[:process] == "checkout") || (item.protected? && !current_user.is_admin?)
                              %select{:name => "order[order_items][#{item.id}][price_list_id][]"}
                                - @price_lists.each do |price_list|
                                  %option{:value => price_list.id, :selected => ('selected' if price_list == item.price_list)}="#{price_list.name}"
                            - else
                              %input{:type => "hidden", :value => item.price_list.id.to_s, :name => "order[order_items][#{item.id}][price_list_id][]"}
                              = "#{item.price_list.name}"
                      - unless item.gallery.nil?
                        %tr
                          %td{:colspan => 2}
                            %span.add_more_from_gallery
                              Add more from
                              %a{:href => gallery_url(item.gallery), :title => "Add more photos from #{item.gallery.name}"}= item.gallery.name
                  %td
                    - unless item.available_item_options.empty?
                      %table.additional_options
                        %tr
                          %td.title{:colspan => 2} Photo Options
                        - item.available_item_options.each do |item_option|
                          %tr
                            %td.check_box
                              - if params[:process] == "checkout"
                                %img{:src => "#{(item.item_options.include?(item_option) ? unavailable_checked : unavailable_unchecked)}", :title => "#{(item.item_options.include?(item_option) ? 'This item was part of this order' : 'This item was not part of this order')}", :alt => "#{(item.item_options.include?(item_option) ? 'This item was part of this order' : 'This item was not part of this order')}"}
                              - else
                                = check_box_tag("order[order_items][#{item.id}][item_options_ids][]", item_option.id, item.item_options.include?(item_option))
                            %td.field
                              = "#{item_option.name} ($#{to_money(item_option.cost)})"
                %tr
                  %td{:colspan => 4}
                    %hr.order_seperator
              - if item.video
                %input{:type => "hidden", :value => item.video.id, :name => "order[order_items][#{item.id}][video_id][]"}
                %tr
                  %td.item_metadata
                    %table.item_metadata{:border => 0}
                      %tr
                        %td.added_on{:colspan => 2}
                          Added on
                          = item.created_at.strftime("%B %o at %I:%M %p")
                          by
                          %a{:href => user_url(item.user), :title => "#{item.user.login}'s profile"}= item.user.login
                      - unless (params[:process] == "checkout") || (item.protected? && !current_user.is_admin?)
                        %tr.remove
                          %td.remove remove
                          %td.check_box= check_box_tag("order[order_items][#{item.id}][remove][]", 1)
                      - if item.protected?
                        %tr
                          %td
                          %td
                            %img.lock{:src => lock_image, :title => "This photo can not be removed", :alt => "This photo can not be removed"}
                  %td.order_video
                    %table.video
                      %tr
                        %td.video
                          %a{:href => video_url(item.video), :title => (item.video.caption ? item.video.caption : item.video.filename), :alt => (item.video.caption ? item.video.caption : item.video.filename)}
                            %img.video_thumb{:src => item.video.thumbnail, :title => (item.video.caption ? item.video.caption : item.video.filename), :alt => (item.video.caption ? item.video.caption : item.video.filename)}
                  %td
                    %table.item_info
                      %tr
                        %td.field_title Quantity:
                        %td.field
                          - unless (params[:process] == "checkout") || (item.protected? && !current_user.is_admin?)
                            %select{:name => "order[order_items][#{item.id}][quantity][]"}
                              - quantities.each do |quantity|
                                %option{:value => quantity, :selected => ('selected' if quantity.to_s == item.quantity.to_s)}= quantity
                          - else
                            %input{:type => "hidden", :value => item.quantity.to_s, :name => "order[order_items][#{item.id}][quantity][]"}
                            = item.quantity.to_s
                      - unless item.gallery.nil?
                        %tr
                          %td{:colspan => 2}
                            %span.add_more_from_gallery
                              Add more from
                              %a{:href => gallery_url(item.gallery), :title => "Add more photos from #{item.gallery.name}"}= item.gallery.name
                
                  %td
                    - unless item.available_item_options.empty?
                      %table.additional_options
                        %tr
                          %td.title{:colspan => 2} Delivery Options:
                        - item.available_item_options.each do |item_option|
                          %tr
                            %td.check_box
                              = check_box_tag("order[order_items][#{item.id}][item_options_ids][]", item_option.id, item.item_options.include?(item_option))
                            %td.field
                              = "#{item_option.name} ($#{to_money(item_option.cost)})"
                %tr
                  %td{:colspan => 4}
                    %hr.order_seperator
            %tr
              %td.order_options{:colspan => 4}
                %h3.options
                  %a Senior Photo Order Options
                %div.options
                  %table.order_options{:align => "right"}
                    - @order_options.each do |order_option|
                      - unless params[:process] == "checkout"
                        - if order_option.quantifiable?
                          %tr
                            %td.order_option= "#{order_option.name} ($#{to_money(order_option.cost)})"
                            %td
                              %select{:name => "order[order_options][#{order_option.id}][quantity][]"}
                                - quantities.each do |quantity|
                                  %option{:value => quantity, :selected => ('selected' if order_option.has_quantity_in?(quantity, order))}= quantity
                        - else
                          %tr
                            %td.order_option= "#{order_option.name} ($#{to_money(order_option.cost)})"
                            %td= check_box_tag("order[order_options][#{order_option.id}][quantity][]", order_option.id, order.order_options.include?(order_option))
                      - else
                        - if order_option.quantifiable?
                          %tr
                            %td.order_option= "#{order_option.name} ($#{to_money(order_option.cost)})"
                            %td
                              - quantities.each do |quantity|
                                - @flag = false
                                - if order_option.has_quantity_in?(quantity, order)
                                  = "[#{quantity}]"
                                  - @flag = true
                              - unless @flag
                                [0]
                        - else
                          %tr
                            %td.order_option= "#{order_option.name} ($#{to_money(order_option.cost)})"
                            %td.check_box
                              %img{:src => "#{(order.order_options.include?(order_option) ? unavailable_checked : unavailable_unchecked)}", :title => "#{(order.order_options.include?(order_option) ? 'This item was part of this order' : 'This item was not part of this order')}", :alt => "#{(order.order_options.include?(order_option) ? 'This item was part of this order' : 'This item was not part of this order')}"}
            %tr
              %td.order_shipping_and_total_info{:colspan => 4}
                %table.order_shipping_and_total_info
                  %tr
                    %td.field_title Shipping Method:
                    %td.field
                      - unless params[:process] == "checkout"
                        %select{:name => "order[shipping_method_id]"}
                          - @shipping_methods.each do |shipping_method|
                            %option{:value => shipping_method.id, :selected => ('selected' if order.shipping_method == shipping_method)}= "#{shipping_method.name} ($#{to_money(shipping_method.cost)})"
                      - else
                        = "#{order.shipping_method.name} ($#{to_money(order.shipping_method.cost)})"
                  %tr
                    %td.field_title Tax:
                    %td.field="$#{to_money(order.tax)}"
                  %tr
                    %td.field_title Order total:
                    %td.field= "$#{to_money(order.grand_total)}"
            - unless params[:process] == "checkout"
              - if @dont_display_this #current_user.is_admin?
                %tr
                  %td.item_submit{:colspan => 4} 
                    Mark order as complete
                    = check_box_tag("order[is_completed]", 1, order.is_completed?)
              %tr
                %td.item_submit{:colspan => 4}= submit_tag 'update order'
              %tr
                %td.item_submit{:colspan => 4}= submit_tag 'checkout'
        - if params[:process] == "checkout"
          %table.checkout
            %tr
              %td.item_submit{:colspan => 4}
                %form{:action => google_checkout_url, :"accept-charset" => "utf-8", :method => "POST"}
                  - order.items.each do |item|
                    - if item.photo
                      %input{:type => "hidden", :name => "item_name_1#{item.id}", :value => "Photo: #{item.photo.filename}"}
                      %input{:type => "hidden", :name => "item_description_1#{item.id}", :value => h(item.description)}
                      %input{:type => "hidden", :name => "item_price_1#{item.id}", :value => to_money(item.cost)}
                      %input{:type => "hidden", :name => "item_currency_1#{item.id}", :value => "USD"}
                      %input{:type => "hidden", :name => "item_quantity_1#{item.id}", :value => item.quantity}
                      %input{:type => "hidden", :name => "item_merchant_id_1#{item.id}", :value => "photo_" + item.id.to_s}
                      - item.item_options.each do |item_option|
                        %input{:type => "hidden", :name => "item_name_2#{item.id.to_s << item_option.id.to_s}", :value => "#{item_option.name}"}
                        %input{:type => "hidden", :name => "item_description_2#{item.id.to_s << item_option.id.to_s}", :value => "Added option for #{item.photo.filename}"}
                        %input{:type => "hidden", :name => "item_price_2#{item.id.to_s << item_option.id.to_s}", :value => to_money(item_option.cost)}
                        %input{:type => "hidden", :name => "item_currency_2#{item.id.to_s << item_option.id.to_s}", :value => "USD"}
                        %input{:type => "hidden", :name => "item_quantity_2#{item.id.to_s << item_option.id.to_s}", :value => "1"}
                        %input{:type => "hidden", :name => "item_merchant_id_2#{item.id.to_s << item_option.id.to_s}", :value => "photo_option_" + item_option.id.to_s}
                    - if item.video
                      %input{:type => "hidden", :name => "item_name_3#{item.id}", :value => "Video: #{item.video.filename}"}
                      %input{:type => "hidden", :name => "item_description_3#{item.id}", :value => h(item.description)}
                      %input{:type => "hidden", :name => "item_price_3#{item.id}", :value => to_money(item.cost)}
                      %input{:type => "hidden", :name => "item_currency_3#{item.id}", :value => "USD"}
                      %input{:type => "hidden", :name => "item_quantity_3#{item.id}", :value => item.quantity}
                      %input{:type => "hidden", :name => "item_merchant_id_3#{item.id}", :value => "video_" + item.id.to_s}
                      - item.item_options.each do |item_option|
                        %input{:type => "hidden", :name => "item_name_4#{item.id.to_s << item_option.id.to_s}", :value => "#{item_option.name}"}
                        %input{:type => "hidden", :name => "item_description_4#{item.id.to_s << item_option.id.to_s}", :value => "Added option for #{item.video.filename}"}
                        %input{:type => "hidden", :name => "item_price_4#{item.id.to_s << item_option.id.to_s}", :value => to_money(item_option.cost)}
                        %input{:type => "hidden", :name => "item_currency_4#{item.id.to_s << item_option.id.to_s}", :value => "USD"}
                        %input{:type => "hidden", :name => "item_quantity_4#{item.id.to_s << item_option.id.to_s}", :value => "1"}
                        %input{:type => "hidden", :name => "item_merchant_id_4#{item.id.to_s << item_option.id.to_s}", :value => "video_option_" + item_option.id.to_s}
                  - order.order_extras.each do |order_extra|
                    %input{:type => "hidden", :name => "item_name_5#{order_extra.order_option.id}", :value => h(order_extra.order_option.name)}
                    %input{:type => "hidden", :name => "item_description_5#{order_extra.order_option.id}", :value => "Additional order option"}
                    %input{:type => "hidden", :name => "item_price_5#{order_extra.order_option.id}", :value => to_money(order_extra.order_option.cost)}
                    %input{:type => "hidden", :name => "item_currency_5#{order_extra.order_option.id}", :value => "USD"}
                    %input{:type => "hidden", :name => "item_quantity_5#{order_extra.order_option.id}", :value => (order_extra.quantity ? order_extra.quantity : "1")}
                    %input{:type => "hidden", :name => "item_merchant_id_5#{order_extra.order_option.id}", :value => order_extra.order_option.id}
                  - @shipping_methods.each do |shipping_method|
                    %input{:type => "hidden", :name => "ship_method_name_5#{shipping_method.id}", :value => h(shipping_method.name)}
                    %input{:type => "hidden", :name => "ship_method_price_5#{shipping_method.id}", :value => to_money(shipping_method.cost)}
                    %input{:type => "hidden", :name => "ship_method_us_area_5#{shipping_method.id}", :value => "FULL_50_STATES"}
                  %input{:type => "hidden", :name => "tax_rate", :value => "0.06"}
                  %input{:type => "hidden", :name => "tax_us_state", :value => "MI"}
                  %input{:type => "hidden", :name => "_charset_"}
                  %input{:type => "hidden", :name => "edit_url", :value => order_url(order)}
                  %input{:type => "hidden", :name => "continue_url", :value => home_url}
                  %input{:type => "image", :name => "Google Checkout", :alt => "Fast checkout through Google", :src => google_checkout_button_url, :height => "43", :width => "160"}
  %hr